import { Body, Controller, Request, Post, Get, Param } from '@nestjs/common';
import { CartsService } from '../services/carts.service';
import { CreateCartDto } from '../dto/create_cart.dto';
import { User } from '@/modules/User/types';
import { Public } from '@/modules/core/decorators/publicGuards';
import { MutilUpdateCart } from '../dto/mutil_update_cart.dto';

@Controller('carts')
export class CartsController {
  constructor(private readonly cartService: CartsService) {}
  @Post('create')
  async create(@Request() req, @Body() body: CreateCartDto) {
    return await this.cartService.create(req.user as User, body);
  }

  @Get('list')
  async list(@Request() req) {
    return await this.cartService.list(req.user as User);
  }
  @Post('update/:id')
  async update(@Param('id') id: string, @Body() body: CreateCartDto) {
    const res = await this.cartService.update(id, body);
    return {
      statusCode: 200,
      message: '更新成功',
      ...res,
    };
  }
  @Post('mutil_update')
  async mutilUpdate(@Body() body: MutilUpdateCart[]) {
    const res = await this.cartService.mutilUpdate(body);
    return {
      statusCode: 200,
      message: '更新成功',
      ...res,
    };
  }
}
